<?php
class UsersEntityBase extends EntityBase
{
	public $id;
	public $username;
	public $email;
	public $password;
	public $firstName;
	public $lastName;
	public $birthday;
	public $countryId;
	public $state;
	public $city;
	public $address;
	public $zipCode;
	public $house;
	public $telephone;
	public $userType;
	public $lastVisit;
	public $activationCode;
	public $gender;
	public $viewed;
	public $status;
	public $createdDate;
	public $modifiedDate;
	public $hasVerified;
	public $picture;
	public $bio;
	public $packageOptionId;



	const INACTIVE = 0;
	const ACTIVE = 1;
	const SUSPENDED = 2;
	const BLOCKED = 3;
	public function __construct($arrValue = null, $prefix = '')
	{
		if(!is_null($arrValue) && is_array($arrValue))
		{
			$this->id = (int) ($arrValue[$prefix . 'id']);
			$this->username = strval ($arrValue[$prefix . 'username']);
			$this->email = strval ($arrValue[$prefix . 'email']);
			$this->password = strval ($arrValue[$prefix . 'password']);
			$this->firstName = strval ($arrValue[$prefix . 'firstName']);
			$this->lastName = strval ($arrValue[$prefix . 'lastName']);
			$this->birthday = strval ($arrValue[$prefix . 'birthday']);
			$this->countryId = strval ($arrValue[$prefix . 'countryId']);
			$this->state = strval ($arrValue[$prefix . 'state']);
			$this->city = strval ($arrValue[$prefix . 'city']);
			$this->address = strval ($arrValue[$prefix . 'address']);
			$this->zipCode = strval ($arrValue[$prefix . 'zipCode']);
			$this->house = strval ($arrValue[$prefix . 'house']);
			$this->telephone = strval ($arrValue[$prefix . 'telephone']);
			$this->userType = strval ($arrValue[$prefix . 'userType']);
			$this->lastVisit = strval ($arrValue[$prefix . 'lastVisit']);
			$this->activationCode = strval ($arrValue[$prefix . 'activationCode']);
			$this->gender = strval ($arrValue[$prefix . 'gender']);
			$this->status = (int) ($arrValue[$prefix . 'status']);
			$this->viewed = (int) ($arrValue[$prefix . 'viewed']);
			$this->createdDate = strval ($arrValue[$prefix . 'createdDate']);
			$this->modifiedDate = strval ($arrValue[$prefix . 'modifiedDate']);
			$this->hasVerified = (int) ($arrValue[$prefix . 'hasVerified']);
			$this->bio = strval ($arrValue[$prefix . 'bio']);
			$this->picture = strval ($arrValue[$prefix . 'picture']);
			$this->packageOptionId = strval ($arrValue[$prefix . 'packageOptionId']);
		}
	}

	/**
	 * Check the role of the user whether his role is Admin or not
	 *
	 * @return bool true if user is ADMIN else false
	 */
	public function isAdministrator($status = self::ACTIVE)
	{
		if (is_null($this->userType)){
			return false;
		}

		if($this->userType == ROLE_ADMIN || $this->userType == ROLE_ADMIN_SUPER){
			return true;
		}

		return false;
	}




	/**
	 * Check the role of the user whether his role is Member (Independent customer) or not
	 *
	 * @return bool true if user is Member (Independent customer) else false
	 */
	public function isMember($status = self::ACTIVE)
	{
		if (is_null($this->userType)){
			return false;
		}

		if($this->userType == ROLE_MEMBER){
			return true;
		}

		return false;
	}


	/**
	 * Get status name of users
	 *
	 * @access public
	 *
	 * @return string name of status
	 *
	 */
	public function getStatusName()
	{
		$arrStatusList = self::getStatusList();
		return isset($arrStatusList["{$this->status}"]) ? $arrStatusList["{$this->status}"] : '';
	}

	/**
	 * Get type name of users
	 *
	 * @access public
	 *
	 * @return string name of type of user
	 *
	 */
	public function getUserTypeName()
	{
		$arrUserTypeList = self::getUserTypeList();
		return isset($arrUserTypeList["{$this->userType}"]) ? $arrUserTypeList["{$this->userType}"] : '';
	}

	/**
	 * Get list of users status
	 *
	 * @access public
	 *
	 * @return array of users status
	 *
	 */
	public static function getStatusList()
	{
		return array(self::INACTIVE	=> 'INACTIVE',
		self::ACTIVE 	=>'ACTIVE',
		self::SUSPENDED =>'SUSPENDED',
		self::BLOCKED  	=>'BLOCKED'
		);
	}

	/**
	 * Get Verified Status
	 *
	 * @access public
	 *
	 * @return array of users status
	 *
	 */
	public static function getVerifyStatusList()
	{
		return array(self::INACTIVE	=> 'NOT VERIFIED',
		self::ACTIVE 	=> 'VERIFIED'
		);
	}

	public function getVerifyStatusName()
	{
		$arrVerifyStatusList = self::getVerifyStatusList();
		return isset($arrVerifyStatusList["{$this->hasVerified}"]) ? $arrVerifyStatusList["{$this->hasVerified}"] : '';
	}

	/**
	 * Get all customer types
	 *
	 * @return array of customer type
	 */
	public static function getCustomerTypeList()
	{
		return array(ROLE_MEMBER => 'MEMBER');
	}

	/**
	 * Get ADMIN and Supervisor types of user
	 *
	 * @return array of ADMIN and supervisor types
	 */
	public static function getAdminTypeList()
	{
		return array(ROLE_ADMIN => 'ADMIN',
		ROLE_ADMIN_SUPER => 'ADMIN_SUPER'
		);
	}

	/**
	 * Get all types of user
	 *
	 * @return array of user type
	 */
	public static function getUserTypeList()
	{
		return array(ROLE_ADMIN 	=> 'ADMIN',
		ROLE_ADMIN_SUPER 	=> 'ADMIN_SUPER',
		ROLE_MEMBER 	=> 'MEMBER');
	}

	/**
	 * Get MEMBER types of user
	 *
	 * @return array of user type
	 */
	public static function getMemberUserTypeList()
	{
		return array(
		ROLE_MEMBER 	=> 'MEMBER');
	}
	
/**
	 * Get all normal admin types
	 *
	 * @return array of customer type
	 */
	public static function getNormalAdminTypeList()
	{
		return array(ROLE_ADMIN => 'ADMIN');
	}

	/**
	 * Get all fields for selecting columns
	 *
	 * @param string $alias: alias of table
	 * @param string $prefix
	 * @return string
	 */
	public static function getSelectColumns($alias, $prefix = '')
	{
		$arrValue = array(
						"{$alias}.id AS `{$prefix}id`",
						"{$alias}.username AS `{$prefix}username`",
						"{$alias}.email AS `{$prefix}email`",
						"{$alias}.password AS `{$prefix}password`",
						"{$alias}.firstName AS `{$prefix}firstName`",
						"{$alias}.lastName AS `{$prefix}lastName`",
						"{$alias}.birthday AS `{$prefix}birthday`",
						"{$alias}.countryId AS `{$prefix}countryId`",
						"{$alias}.state AS `{$prefix}state`",
						"{$alias}.city AS `{$prefix}city`",
						"{$alias}.address AS `{$prefix}address`",
						"{$alias}.zipCode AS `{$prefix}zipCode`",
						"{$alias}.house AS `{$prefix}house`",
						"{$alias}.telephone AS `{$prefix}telephone`",
						"{$alias}.userType AS `{$prefix}userType`",
						"{$alias}.activationCode AS `{$prefix}activationCode`",
						"{$alias}.gender AS `{$prefix}gender`",
						"{$alias}.lastVisit AS `{$prefix}lastVisit`",
						"{$alias}.status AS `{$prefix}status`",
						"{$alias}.viewed AS `{$prefix}viewed`",
						"{$alias}.createdDate AS `{$prefix}createdDate`",
						"{$alias}.modifiedDate AS `{$prefix}modifiedDate`",
						"{$alias}.hasVerified AS `{$prefix}hasVerified`",
						"{$alias}.bio AS `{$prefix}bio`",
						"{$alias}.picture AS `{$prefix}picture`",
						"{$alias}.packageOptionId AS `{$prefix}packageOptionId`",												
		);

		return implode(',', $arrValue);
	}
}